package com.cjm.one.webmanager.service.system.impl;

import com.cjm.one.common.exception.GlobalException;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.base.TokenVo;
import com.cjm.one.model.auth.system.dto.LoginDto;
import com.cjm.one.model.auth.system.vo.CaptchaCodeVo;
import com.cjm.one.model.system.entity.SysResource;
import com.cjm.one.model.system.vo.SysResourceVo;
import com.cjm.one.system.client.SyStemUserClient;
import com.cjm.one.webmanager.service.system.SysLoginService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service

public class SysLoginServiceImpl implements SysLoginService {

    @Resource
    private SyStemUserClient syStemUserClient;

    @Override
    public TokenVo login(LoginDto loginDto) {
        Result<TokenVo> login = syStemUserClient.login(loginDto);
        if (login.getCode().equals(200)) {
            return login.getData();
        }
        throw new GlobalException(login.getCode(), login.getMessage());

    }

    @Override
    public CaptchaCodeVo getCaptchaCode() {
//        log.info("获取验证码:{}",syStemUserClient.getCaptchaCode().getData());
        return syStemUserClient.getCaptchaCode().getData();
    }

    @Override
    public List<SysResourceVo> getAllMenuList() {
        List<SysResourceVo> data = syStemUserClient.getAllMenuList().getData();
        log.info("获取所有菜单:{}",data);
        return data;
    }
}
